class Node{
    int val;
    Node next;
    public Node(){}

    public Node(int val,Node node){
        this.val = val;
        this.next = node;
    }

}

public class MyStackLinked {
    Node head;// 头节点 : 标记栈顶

    public void push(int x){
        Node node = new Node(x,head);
            this.head = node;
    }

    public int pop(){
        if(isEmpty()){
            throw  new RuntimeException("栈为空");
        }
        int oldVal = this.head.val;
        head = head.next;
        return oldVal;
    }
    public boolean isEmpty(){
        return this.head == null;
    }

    public int peek(){
        if(isEmpty()){
            throw  new RuntimeException("栈为空");
        }
        return head.val;
    }
}
